import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete } from "@/utils/axios";
import { AssetGateway } from "@/api/backend/index";

export const useAssetGateway = defineStore(Names.AssetGateway, {
  state: () => {
    return {
      single: <any>{},
      typeOnline: <any>[],
      typeSwitch: <any>[],
      typeUplinkMode: <any>[], //网关上行通讯方式
      typeDownlinkMode: <any>[], //网关下行通讯方式
      tags: <any>{},
      sites: <any>{}, //站点map
      editsiteName: "", //编辑表单待查站点名称
    };
  },
  getters: {},
  actions: {
    //获取网关列表数据
    getList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(AssetGateway + "/list", filter, "json", "")
          .then((res: any) => {
            console.log("获取网关列表数据", res);
            resolve(res.rows);
          })
          .catch((err: any) => {
            console.log(err);
            reject(err);
          });
      });
    },
    //使用id过滤
    getfilterById(filter: any) {
      return new Promise((resolve, reject) => {
        _get(AssetGateway + `/${filter.siteId}`, {}, "json", "")
          .then(async (res: any) => {
            console.log("使用id过滤", res);
            resolve(res.data);
          })
          .catch((err) => {
            console.log(err);
            reject(err);
          });
      });
    },
  },
});
